package com.im.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.im.service.dto.FuncMenu;
import com.im.service.dto.Staff;
import com.im.service.user.smo.IUserQuerySMO;
import com.im.util.ReturnsUtil;

@Controller
@RequestMapping("userController")
public class UserController extends BaseController {
	
	private static final Logger logger = LogManager.getLogger(UserController.class);

	@Autowired
    private IUserQuerySMO userQuerySMO;
	
	
    /**
     * 首页
     * @return
     */
    @RequestMapping("/index")
    public String blacklist(Model model,HttpServletRequest request){
        super.putMDA(model);
        //查询菜单权限
        HttpSession session = request.getSession();
        //if(session.getAttribute("projectMenus") == null){
        Staff staff = (Staff) session.getAttribute("loginedStaff");
        if(staff==null){
            return "login/login";
        }
        model.addAttribute("staffId",staff.getStaffId());
        model.addAttribute("staffName",staff.getName());
        //查询菜单权限
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("staffId", staff.getStaffId());
        queryMap.put("funcMenus", "Y");

        List<FuncMenu> funcMenus = userQuerySMO.queryStaffFuncMenus(queryMap);
        logger.debug("加载菜单信息为：" + ReturnsUtil.returnSuccess(funcMenus));
        request.setAttribute("projectMenus", funcMenus);
        request.setAttribute("userName", staff.getName());
        //}

        return "index";
    }

    @RequestMapping("/userManage")
    public String userManage(Model model){
        super.putMDA(model);
        return "systemmanage/userManage";
    }
    @RequestMapping("/roleManage")
    public String roleManage(Model model){
        super.putMDA(model);
        return "systemmanage/roleManage";
    }
    @RequestMapping("/menuManage")
    public String usermenuManageManage(Model model){
        super.putMDA(model);
        return "systemmanage/menuManage";
    }
    @RequestMapping("/unitManage")
    public String unitManage(Model model){
        super.putMDA(model);
        return "systemmanage/unitManage";
    }
    @RequestMapping("/constantManage")
    public String constantManage(Model model){
        super.putMDA(model);
        return "systemmanage/constantManage";
    }
    @RequestMapping("/fileTempManage")
    public String fileTempManage(Model model){
        super.putMDA(model);
        return "systemmanage/fileTempManage";
    }
    @RequestMapping("/passwordChange")
    public String passwordChange(Model model){
        super.putMDA(model);
        return "passwordManage/passwordChange";
    }
    @RequestMapping("/passwordReset")
    public String passwordReset(Model model){
        super.putMDA(model);
        return "passwordManage/resetPassword";
    }

	@RequestMapping("/print")
	public String print(Model model) {
		super.putMDA(model);
		return "print";
	}

}
